package com.apes.framework.plugin.form.parser.element;

import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.form.parser.node.FormNodeParser;
import com.apes.framework.util.MapUtil;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 功能：link解析
 *
 * @author xul
 * @create 2022-06-13 09:12
 */
@Component
public class LinkElementParser extends AbstractElementParser {

    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"link"};

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return FormNodeParser.domain;
    }

    /**
     * 功能：可解析的元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    @Override
    public Map parse(ApesElement element) {
        Map node = new HashMap();
        parseAttributes(node, element);
        return MapUtil.mapper("link", node);
    }

    protected void parseAttributes(Map node, ApesElement element) {
        element.getAttributes().forEach((k, v) -> {
            node.put(k.trim(), v.trim());
        });
    }

}
